From: Paul Gevers Date: Thu, 10 Sep 2020 19:24:29 +0000 (+0200) Subject: Add patches to fix issues found by valgrind on mips*el X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~14 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=6e467db8ebe731ab5d536a0baefa65b6175d3142;p=siridb-server.git Add patches to fix issues found by valgrind on mips*el --- diff --git a/debian/patches/0001-Added-missing-import.patch b/debian/patches/0001-Added-missing-import.patch new file mode 100644 index 00000000..6ed7d36a --- /dev/null +++ b/debian/patches/0001-Added-missing-import.patch @@ -0,0 +1,24 @@ +From 48b930bec18ecdbce9f1c207b99b994a0d356f43 Mon Sep 17 00:00:00 2001 +From: Jeroen van der Heijden +Date: Thu, 10 Sep 2020 16:47:25 +0200 +Subject: [PATCH] Added missing import + +--- + include/siri/grammar/gramp.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/include/siri/grammar/gramp.h b/include/siri/grammar/gramp.h +index f2796951..df8d81f9 100644 +--- a/include/siri/grammar/gramp.h ++++ b/include/siri/grammar/gramp.h +@@ -11,6 +11,7 @@ + #define SIRI_GRAMP_H_ + + #include ++#include + + /* keywords */ + #define KW_OFFSET CLERI_GID_K_ACCESS +-- +2.28.0 + diff --git a/debian/patches/0001-Fixes-32-bit-compile-issue-135.patch b/debian/patches/0001-Fixes-32-bit-compile-issue-135.patch new file mode 100644 index 00000000..676c289b --- /dev/null +++ b/debian/patches/0001-Fixes-32-bit-compile-issue-135.patch @@ -0,0 +1,290 @@ +From 270b1951d67634aa9f71ef4f859e2225bb20afae Mon Sep 17 00:00:00 2001 +From: Jeroen van der Heijden +Date: Thu, 10 Sep 2020 15:37:15 +0200 +Subject: [PATCH] Fixes 32 bit compile issue, #135 + +--- + include/llist/llist.h | 2 + + include/siri/db/query.h | 8 ++++ + include/siri/grammar/gramp.h | 5 +++ + include/siri/inc.h | 14 +++++++ + include/siri/version.h | 4 +- + src/llist/llist.c | 19 ++++++++++ + src/siri/db/query.c | 71 ++++++++++++++++++++++++++++++++++-- + 7 files changed, 118 insertions(+), 5 deletions(-) + create mode 100644 include/siri/inc.h + +diff --git a/include/llist/llist.h b/include/llist/llist.h +index e5c57250..b49bc6fe 100644 +--- a/include/llist/llist.h ++++ b/include/llist/llist.h +@@ -11,9 +11,11 @@ typedef struct llist_node_s llist_node_t; + #include + + typedef int (*llist_cb)(void * data, void * args); ++typedef void (*llist_destroy_cb)(void * data); + + llist_t * llist_new(void); + void llist_free_cb(llist_t * llist, llist_cb cb, void * args); ++void llist_destroy(llist_t * llist, llist_destroy_cb cb); + int llist_append(llist_t * llist, void * data); + int llist_walk(llist_t * llist, llist_cb cb, void * args); + void llist_walkn(llist_t * llist, size_t * n, llist_cb cb, void * args); +diff --git a/include/siri/db/query.h b/include/siri/db/query.h +index fbe2ef76..b7f8971f 100644 +--- a/include/siri/db/query.h ++++ b/include/siri/db/query.h +@@ -44,6 +44,11 @@ typedef struct siridb_query_s siridb_query_t; + #include + #include + #include ++#include ++ ++#if SIRIDB_EXPR_ALLOC ++#include ++#endif + + void siridb_query_run( + uint16_t pid, +@@ -83,6 +88,9 @@ struct siridb_query_s + cleri_parse_t * pr; + siridb_nodes_t * nodes; + struct timespec start; ++#if SIRIDB_EXPR_ALLOC ++ llist_t * expr_cache; ++#endif + }; + + #endif /* SIRIDB_QUERY_H_ */ +diff --git a/include/siri/grammar/gramp.h b/include/siri/grammar/gramp.h +index 1c1826f9..f2796951 100644 +--- a/include/siri/grammar/gramp.h ++++ b/include/siri/grammar/gramp.h +@@ -26,9 +26,14 @@ + + + #if CLERI_VERSION_MINOR >= 12 ++#if SIRIDB_IS64BIT + #define CLERI_NODE_DATA(__node) ((int64_t)(__node)->data) + #define CLERI_NODE_DATA_ADDR(__node) ((int64_t *) &(__node)->data) + #else ++#define CLERI_NODE_DATA(__node) *((int64_t *)(__node)->data) ++#define CLERI_NODE_DATA_ADDR(__node) ((int64_t *)(__node)->data) ++#endif ++#else + #define CLERI_NODE_DATA(__node) (__node)->result + #define CLERI_NODE_DATA_ADDR(__node) &(__node)->result + #endif +diff --git a/include/siri/inc.h b/include/siri/inc.h +new file mode 100644 +index 00000000..c55c7c12 +--- /dev/null ++++ b/include/siri/inc.h +@@ -0,0 +1,14 @@ ++#if UINTPTR_MAX == 0xffffffff ++#define SIRIDB_IS64BIT 0 ++#elif UINTPTR_MAX == 0xffffffffffffffff ++#define SIRIDB_IS64BIT 1 ++#else ++#define SIRIDB_IS64BIT __WORDSIZE == 64 ++#endif ++ ++ ++#if SIRIDB_IS64BIT ++#define SIRIDB_EXPR_ALLOC 0 ++#else ++#define SIRIDB_EXPR_ALLOC CLERI_VERSION_MINOR >= 12 ++#endif +diff --git a/include/siri/version.h b/include/siri/version.h +index ac332a39..26b90996 100644 +--- a/include/siri/version.h ++++ b/include/siri/version.h +@@ -6,7 +6,7 @@ + + #define SIRIDB_VERSION_MAJOR 2 + #define SIRIDB_VERSION_MINOR 0 +-#define SIRIDB_VERSION_PATCH 38 ++#define SIRIDB_VERSION_PATCH 39 + + /* + * Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions. +@@ -15,7 +15,7 @@ + * Note that debian alpha packages should use versions like this: + * 2.0.34-0alpha0 + */ +-#define SIRIDB_VERSION_PRE_RELEASE "" ++#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0" + + #ifndef NDEBUG + #define SIRIDB_VERSION_BUILD_RELEASE "+debug" +diff --git a/src/llist/llist.c b/src/llist/llist.c +index 893ed363..adb8aa91 100644 +--- a/src/llist/llist.c ++++ b/src/llist/llist.c +@@ -42,6 +42,25 @@ void llist_free_cb(llist_t * llist, llist_cb cb, void * args) + free(llist); + } + ++/* ++ * Destroys the linked list and calls a call-back function on each item. ++ * The result of the call back function will be ignored. ++ */ ++void llist_destroy(llist_t * llist, llist_destroy_cb cb) ++{ ++ llist_node_t * node = llist->first; ++ llist_node_t * next; ++ ++ while (node != NULL) ++ { ++ cb(node->data); ++ next = node->next; ++ free(node); ++ node = next; ++ } ++ free(llist); ++} ++ + /* + * Appends to the end of the list. + * +diff --git a/src/siri/db/query.c b/src/siri/db/query.c +index ae744d09..941614a7 100644 +--- a/src/siri/db/query.c ++++ b/src/siri/db/query.c +@@ -25,6 +25,11 @@ + #include + #include + ++#if SIRIDB_EXPR_ALLOC ++#include ++#endif ++ ++ + #define QUERY_TOO_LONG -1 + #define QUERY_MAX_LENGTH 8192 + #define QUERY_EXTRA_ALLOC_SIZE 200 +@@ -32,7 +37,12 @@ + + static void QUERY_send_invalid_error(uv_async_t * handle); + static void QUERY_parse(uv_async_t * handle); +-static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker); ++static int QUERY_walk( ++#if SIRIDB_EXPR_ALLOC ++ siridb_query_t * query, ++#endif ++ cleri_node_t * node, ++ siridb_walker_t * walker); + static int QUERY_to_packer(qp_packer_t * packer, siridb_query_t * query); + static int QUERY_time_expr( + cleri_node_t * node, +@@ -82,6 +92,17 @@ void siridb_query_run( + return; + } + ++ #if SIRIDB_EXPR_ALLOC ++ if ((query->expr_cache = llist_new()) == NULL) ++ { ++ ERR_ALLOC ++ free(query->q); ++ free(query); ++ free(handle); ++ return; ++ } ++ #endif ++ + /* + * Set start time. + * (must be real time since we translate now with this value) +@@ -160,6 +181,13 @@ void siridb_query_free(uv_handle_t * handle) + cleri_parse_free(query->pr); + } + ++ #if SIRIDB_EXPR_ALLOC ++ if (query->expr_cache != NULL) ++ { ++ llist_destroy(query->expr_cache, (llist_destroy_cb) free); ++ } ++ #endif ++ + /* decrement client reference counter */ + sirinet_stream_decref(query->client); + +@@ -589,6 +617,9 @@ static void QUERY_parse(uv_async_t * handle) + } + + if ((rc = QUERY_walk( ++#if SIRIDB_EXPR_ALLOC ++ query, ++#endif + query->pr->tree->children->node, + walker))) + { +@@ -678,7 +709,12 @@ static int QUERY_to_packer(qp_packer_t * packer, siridb_query_t * query) + return 0; + } + +-static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker) ++static int QUERY_walk( ++#if SIRIDB_EXPR_ALLOC ++ siridb_query_t * query, ++#endif ++ cleri_node_t * node, ++ siridb_walker_t * walker) + { + int rc; + uint32_t gid; +@@ -723,6 +759,18 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker) + /* terminate buffer */ + buffer[EXPR_MAX_SIZE - size] = 0; + ++ #if SIRIDB_EXPR_ALLOC ++ { ++ int64_t * itmp = malloc(sizeof(int64_t)); ++ if (itmp == NULL || llist_append(query->expr_cache, itmp)) ++ { ++ free(itmp); ++ return EXPR_MEM_ALLOC_ERR; ++ } ++ node->data = itmp; ++ } ++ #endif ++ + /* evaluate the expression */ + if ((rc = expr_parse(CLERI_NODE_DATA_ADDR(node), buffer))) + { +@@ -751,6 +799,18 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker) + /* terminate buffer */ + buffer[EXPR_MAX_SIZE - size] = 0; + ++ #if SIRIDB_EXPR_ALLOC ++ { ++ int64_t * itmp = malloc(sizeof(int64_t)); ++ if (itmp == NULL || llist_append(query->expr_cache, itmp)) ++ { ++ free(itmp); ++ return EXPR_MEM_ALLOC_ERR; ++ } ++ node->data = itmp; ++ } ++ #endif ++ + /* evaluate the expression */ + if ((rc = expr_parse(CLERI_NODE_DATA_ADDR(node), buffer))) + { +@@ -770,7 +830,12 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker) + { + current = current->node->children; + } +- if ((rc = QUERY_walk(current->node, walker))) ++ if ((rc = QUERY_walk( ++#if SIRIDB_EXPR_ALLOC ++ query, ++#endif ++ current->node, ++ walker))) + { + return rc; + } +-- +2.28.0 + diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 00000000..9e8f164f --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,2 @@ +0001-Fixes-32-bit-compile-issue-135.patch +0001-Added-missing-import.patch